package com.itheima.mapper;

import com.itheima.pojo.Emp;
import com.itheima.pojo.empQueryParam;
import org.apache.ibatis.annotations.*;

import java.time.LocalDate;
import java.util.List;
import java.util.Map;

@Mapper
public interface EmpMapper {
//原始代码
//    @Select("select count(*) from emp left join dept on emp.dept_id = dept.id")
//    public long count();
//
//    @Select("select emp.*,dept.name deptName from emp left join dept on emp.dept_id = dept.id order by update_time desc limit #{start},#{pageSize}")
//    public List<Emp> getEmps(Integer start,Integer pageSize);
    //@Select("select emp.*,dept.name deptName from emp left join dept on emp.dept_id = dept.id order by update_time desc")

   // public List<Emp>list(String name, Integer gender, LocalDate begin, LocalDate end);

    List<Emp> list(empQueryParam empQueryParam);

    @Options(useGeneratedKeys=true, keyProperty="id")//插入数据后，获取自增主键
    @Insert("insert into emp(username, name, gender, phone, job, salary, image, entry_date, dept_id, create_time, update_time) " +
            "values(#{username}, #{name}, #{gender}, #{phone}, #{job}, #{salary}, #{image}, #{entryDate}, #{deptId}, #{createTime}, #{updateTime}) ")
    void insert(Emp emp);

    void deleteByIds(List<Integer> ids);

    Emp getEmpById(Integer id);

    void update(Emp emp);

    @MapKey("pos")
    List<Map<String ,Object>> countEmpJobData();

    @MapKey("name")
    List<Map<String, Object>> countEmpGenderData();

    @Select("select id,username,name from emp where username = #{username} and password = #{password}")
    Emp SelectBYUsernameandPassword(Emp emp);
}
